﻿///<reference path="../../../../Scripts/jquery-1.4.1-vsdoc.js"/>


function AccordionBase(id, parentControl) {
    var thisId = id;
    this.ParentControl = parentControl;
    this.Container;
    var callBacks = new Dictionary();
    

    this.Container = $("<div>", { id: thisId, className: "accordionContainer" }).appendTo(this.ParentControl);

    this.Render = function () {

        this.Container.accordion({
            icons: false,
            fillSpace: true,
            change: function (event, ui) {
                var title = ui.newHeader.text();
                var callBack = callBacks.Lookup(title);
                if (callBack != undefined)
                    callBack.call();
            }
        });

        window.setTimeout(function () {
            $(window).resize();
        }, 500);

        $(window).resize(function () {
            ChangeWindowHeight(true);
        });
    }

    this.AddNewPanel = function (title, content, onShowCallBack) {
        var panel = $("<h3><a href='#'><span class='smallText'>" + title + "</span></a></h3><div class='accordionPanelContainerParent'><div class='smallText accordionPanelContainer'></div></div>");
        panel.find("div.accordionPanelContainer").append(content);
        this.Container.append(panel);

        if (onShowCallBack != undefined)
            callBacks.Add(title, onShowCallBack);
    }

    function ChangeWindowHeight(first) {
        $("#" + thisId).accordion("resize");        

        if (first) {
            window.setTimeout(function () { ChangeWindowHeight(false); }, 100);  // иначе когда сразу сворачиваем / разворачиваем окно - не работает
        }
    }
}
